1 using UnityEngine;
2 using
System.Collections;
3
4 public
class EnergyBeamScript : MonoBehaviour {
5
6     
public float scaleIncrement = 0.001f;
7     
public float beamLength = 1.0f;
8
9     
private bool isShooting = false;
10     
private float scaleX, scaleY;
11     
// Use this for initialization
12     
void Start () {
13         isShooting =
false;
14         scaleX = transform.localScale.x;
15         scaleY = transform.localScale.y;
16         transform.localScale =
new Vector3(0, 0, 0);
17     
18     }
19     
20     
// Update is called once per frame
21     
void Update () {
22         
if (isShooting) {
23             transform.localScale +=
new Vector3(0, 0, scaleIncrement * Time.deltaTime);
24             
if(transform.localScale.z > beamLength){
25                 isShooting =
false;
26                 transform.localScale =
new Vector3(0, 0, 0);
27             }
28         }
29     
30     }
31
32
33     
void Shoot(){
34
35         
if (isShooting) {
36             
return;
37         }
else {
38             isShooting =
true;
39             transform.localScale =
new Vector3(scaleX, scaleY, 0);
40
41         }
42     }
43 }


Gõ tìm kiếm nhanh...